import request from '~/utils/request'

export interface CategoryItem {
  id: string
  name?: string
  col?: number
  urlname?: string
}

export interface PixelItem {
  tags?: string[]
  author?: string
  authorLike?: string
  avatar?: string
  id: string
  photo?: string
  photoDownLink?: string
  photoHeight?: number
  photoLink?: string
  photoType?: string
  photoWidth?: number
  title?: string
  __v?: number
  _id?: string
}

interface CategoryResponse {
  categories: CategoryItem[]
}

interface PixelResponse {
  list: PixelItem[]
  page: number
  size: number
  total: number
}

type PixelListsReqParams = Pick<PixelResponse, 'page' | 'size'>

// 参考这里：https://juejin.cn/post/7107925960342634533
export function getCategory<T = CategoryResponse>(): Promise<T> {
  return request.get<any, T>('/category')
}

export function getPixelLists<T = PixelResponse>(params: PixelListsReqParams = { page: 1, size: 20 }): Promise<T> {
  return request.get<any, T>('/pixels/list', {
    params,
  })
}
